//
//  HBRealNameViewController.m
//  YHApp
//
//  Created by sy on 2023/11/25.
//

#import "HARealNameVC.h"
#import "HAUserInfoMo.h"
#import "HAChooseTabPopView.h"
#import "HAAddressPopView.h"
#import "YWAlertView.h"
#import "HABankMo.h"

@interface HARealNameVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic ,strong) NSMutableArray *dataArray;

/***/
@property (nonatomic, strong) HAUserInfoMo *model;
/***/
@property (nonatomic, strong) HABankMo *selBankModel;

/***/
@property (nonatomic, strong) UITextField *mobileTextField;
/***/
@property (nonatomic, strong) UITextField *nameTextField;
/***/
@property (nonatomic, strong) UITextField *identityTextField;
/***/
@property (nonatomic, strong) UITextField *bondTextField;
/***/
@property (nonatomic, strong) UITextField *addressTextField;

/***/
@property (nonatomic, strong) NSString *name;
/***/
@property (nonatomic, strong) NSString *identity;
/***/
@property (nonatomic, strong) NSString *region;
/***/
@property (nonatomic, strong) NSString *address;
/***/
@property (nonatomic, strong) NSString *type;

/***/
@property (nonatomic, assign) NSInteger selAddressType;

/***/
@property (nonatomic, strong) UITextField *companyNameTextField;
/***/
@property (nonatomic, strong) UITextField *companyBoosNameTextField;
/***/
@property (nonatomic, strong) UITextField *companyCodeTextField;
/***/
@property (nonatomic, strong) UITextField *companyMoneyTextField;
/***/
@property (nonatomic, strong) UITextField *companyAddressField;

/***/
@property (nonatomic, strong) NSString *company_name;
/***/
@property (nonatomic, strong) NSString *company_legal_person;
/***/
@property (nonatomic, strong) NSString *company_business;
/***/
@property (nonatomic, strong) NSString *company_capital;
/***/
@property (nonatomic, strong) NSString *company_address;
/***/
@property (nonatomic, strong) NSString *company_open_date;
/***/
@property (nonatomic, strong) NSString *company_region;

/***/
@property (nonatomic, strong) UITextField *bankZhihangField;
/***/
@property (nonatomic, strong) UITextField *bankNumberField;
/***/
@property (nonatomic, strong) UITextField *bankUserNameField;
/***/
@property (nonatomic, strong) UITextField *bankMobileField;

/***/
@property (nonatomic, strong) NSString *bank_zhihang;
/***/
@property (nonatomic, strong) NSString *bank_number;

@property (nonatomic, strong) NSString *bank_region;

@property (nonatomic, strong) NSString *bank_userName;

@property (nonatomic, strong) NSString *bank_mobile;


/***/
@property (nonatomic, strong) UITextField *aliNameField;
/***/
@property (nonatomic, strong) UITextField *aliNumberField;

/***/
@property (nonatomic, strong) NSString *ali_name;
/***/
@property (nonatomic, strong) NSString *ali_number;


@property (nonatomic,strong) id <YWAlertViewProtocol>dateAlert;


@end

@implementation HARealNameVC
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.baseTLabel.text = @"实名认证";

    [self initUI];
    [self loadData];
    
    // Do any additional setup after loading the view.
}

- (void)initUI{
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(app_topH+44);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

-(void)loadData {
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodGET;
    request.requestUrl = @"account/info";
    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                self.model = [HAUserInfoMo mj_objectWithKeyValues:dataModel.data];
                
                self.name = self.model.name;
                self.identity = self.model.identity;
                self.region = self.model.region;
                self.address = self.model.address;
//                if (self.model.type==1) {
//                    self.type = @"1";
//                }else {
//                    self.type = @"0";
//                }
                
                self.type = @"0";

//                self.company_name = self.model.company.name;
//                self.company_legal_person = self.model.company.legal_person;
//                self.company_business = self.model.company.business;
//                self.company_capital = self.model.company.capital;
//                self.company_address = self.model.company.address;
//                self.company_open_date = self.model.company.open_date;
//                self.company_region = self.model.company.region;
                
                self.bank_region = self.model.account_bankRegion;
                self.bank_zhihang = self.model.account_bankBranch;
                self.bank_number = self.model.account_bankAccount;
                self.bank_mobile = self.model.account_bankMobile;
                self.bank_userName = self.model.account_surname;
                
                self.ali_number = self.model.account_alipay_no;
                self.ali_name = self.model.account_alipay_account;
                
                HABankMo *selBankModel = [[HABankMo alloc]init];
                selBankModel.name = self.model.account_bankName;
                selBankModel.ID = self.model.account_bankid;
                self.selBankModel = selBankModel;

                [self loadDataArray:self.model.type];
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];

}

-(void)loadDataArray: (NSInteger )is_public {
    
    [self.dataArray removeAllObjects];
    [self.dataArray addObject:@"手机号"];
    [self.dataArray addObject:@"代理名称"];
    [self.dataArray addObject:@"保证金"];
    [self.dataArray addObject:@"省市区/县1"];
    [self.dataArray addObject:@"街道地址"];
    [self.dataArray addObject:@"客户类型"];
    if (is_public == 1) {
        [self.dataArray addObject:@"企业信息"];
        [self.dataArray addObject:@"企业名称"];
        [self.dataArray addObject:@"法人姓名"];
        [self.dataArray addObject:@"机构代码"];
        [self.dataArray addObject:@"注册资本"];
        [self.dataArray addObject:@"注册时间"];
        [self.dataArray addObject:@"省市区/县2"];
        [self.dataArray addObject:@"公司地址"];
    }
    [self.dataArray addObject:@"银联账户"];
    [self.dataArray addObject:@"银行名称"];
    [self.dataArray addObject:@"省市区/县3"];
    [self.dataArray addObject:@"收款支行"];
    [self.dataArray addObject:@"结算法人"];
    [self.dataArray addObject:@"身份证号"];
    [self.dataArray addObject:@"收款卡号"];
    [self.dataArray addObject:@"预留手机号"];

    [self.dataArray addObject:@"支付宝账户"];
    [self.dataArray addObject:@"收款人名称"];
    [self.dataArray addObject:@"支付宝账号"];
    
    [self.dataArray addObject:@"提交"];
    [self.tableView reloadData];
}

-(void)mitButtonClick {
    [self.view endEditing:YES];

    NSDictionary *dict = @{
        @"name":self.name?:@"",
        @"identity":self.identity?:@"",
        @"region1":self.region?:@"",
        @"address":self.address?:@"",
        @"type":self.type?:@"",
//        @"company":@{
//                @"name":self.company_name?:@"",
//                @"legal_person":self.company_legal_person?:@"",
//                @"business":self.company_business?:@"",
//                @"company_capital":self.company_capital?:@"",
//                @"address":self.company_address?:@"",
//        },
//        @"company_open_date":self.company_open_date?:@"",
//        @"company_region":self.company_region?:@"",
        
        @"bank_id":self.selBankModel.ID?:@"",
        @"bank_account":self.bank_number?:@"",
        @"region":self.bank_region?:@"",
        @"branch":self.bank_zhihang?:@"",
        @"mobile":self.bank_mobile?:@"",
        @"surname":self.bank_userName?:@"",
        @"alipay_no":self.ali_number?:@"",
        @"alipay_account":self.ali_name?:@"",
    };
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodPOST;
    request.requestUrl = @"account/profile";
    request.parms = dict;
    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                [MBProgressHUD showSuccess:@"提交成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *title = self.dataArray[indexPath.row];
    if ([title isEqualToString:@"企业信息"] || [title isEqualToString:@"银联账户"] || [title isEqualToString:@"支付宝账户"]) {
        return 64;
    }else if ([title isEqualToString:@"提交"]) {
        return 54+60;
    }
    return 54;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *title = self.dataArray[indexPath.row];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCellID"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCellID"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if ([title isEqualToString:@"手机号"]) {
        [self setCellTextContent:cell.contentView title:title content:self.model.mobile isLine:YES];
    }
    if ([title isEqualToString:@"代理名称"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.name isLine:YES ];
    }
    if ([title isEqualToString:@"身份证号"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.identity isLine:YES];
    }
    if ([title isEqualToString:@"保证金"]) {
        [self setCellTextContent:cell.contentView title:title content:[NSString stringWithFormat:@"%@(万元)",self.model.deposit] isLine:YES];
    }
    if ([title isEqualToString:@"省市区/县1"]) {
        NSString *content = @"请选择";
        if (![NSString isEmptyString:self.region]) {
            content = self.region;
        }
        [self setCellTextContent:cell.contentView title:@"省市区/县" content:content isLine:YES];
    }
    if ([title isEqualToString:@"街道地址"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.address isLine:YES];
    }
    if ([title isEqualToString:@"客户类型"]) {
        NSString *context =  @"";
        if ([self.type isEqualToString:@"1"]) {
            context = @"公司";
        }else {
            context = @"个人";
        }
        [self setCellTextContent:cell.contentView title:title content:context isLine:YES];
    }
    
    if ([title isEqualToString:@"企业信息"]) {
        [self setCellTextContent:cell.contentView title:title content:@"" isLine:NO];
    }else if ([title isEqualToString:@"企业名称"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.company_name isLine:YES];
    }else if ([title isEqualToString:@"法人姓名"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.company_legal_person isLine:YES];
    }else if ([title isEqualToString:@"机构代码"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.company_business isLine:YES];
    }else if ([title isEqualToString:@"注册资本"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.company_capital isLine:YES];
    }else if ([title isEqualToString:@"注册时间"]) {
        [self setCellTextContent:cell.contentView title:title content:self.company_open_date?:@"注册时间" isLine:YES];
    }else if ([title isEqualToString:@"省市区/县2"]) {
        NSString *content = @"请选择";
        if (![NSString isEmptyString:self.company_region]) {
            content = self.company_region;
        }
        [self setCellTextContent:cell.contentView title:@"省市区/县" content:content isLine:YES];
    }else if ([title isEqualToString:@"公司地址"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.company_address isLine:YES];
    }
    
    if ([title isEqualToString:@"银联账户"]) {
        [self setCellTextContent:cell.contentView title:title content:@"" isLine:NO];
    }else if ([title isEqualToString:@"银行名称"]) {
        NSString *content = @"请选择";
        if (self.selBankModel) {
            content = self.selBankModel.name;
        }
        [self setCellTextContent:cell.contentView title:@"银行名称" content:content isLine:YES];
    }else if ([title isEqualToString:@"省市区/县3"]) {
        NSString *content = @"请选择";
        if (![NSString isEmptyString:self.bank_region]) {
            content = self.bank_region;
        }
        [self setCellTextContent:cell.contentView title:@"省市区/县" content:content isLine:YES];
    }else if ([title isEqualToString:@"收款支行"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.bank_zhihang isLine:YES];
    }else if ([title isEqualToString:@"收款卡号"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.bank_number isLine:YES];
    }else if ([title isEqualToString:@"结算法人"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.bank_userName isLine:YES];
    }else if ([title isEqualToString:@"预留手机号"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.bank_mobile isLine:YES];
    }


    if ([title isEqualToString:@"支付宝账户"]) {
        [self setCellTextContent:cell.contentView title:title content:@"" isLine:NO];
    }else if ([title isEqualToString:@"收款人名称"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.ali_name isLine:YES];
    }else if ([title isEqualToString:@"支付宝账号"]) {
        [self setCellFieldContent:cell.contentView title:title content:self.ali_number isLine:YES];
    }
    
    if ([title isEqualToString:@"提交"]) {
        [self setCellMit:cell.contentView];
    }
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.view endEditing:YES];
    WS(weakSelf)
    NSString *title = self.dataArray[indexPath.row];
    if ([title isEqualToString:@"省市区/县1"]) {
        self.selAddressType = 1;
        [self laodAddress];
    }else if ([title isEqualToString:@"客户类型"]) {
//        NSMutableArray *dicts = [NSMutableArray array];
//        [dicts addObject:@{@"color":@"#373737",@"title":@"个人"}];
//        [dicts addObject:@{@"color":@"#373737",@"title":@"公司"}];
//        HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"客户类型"];
//        [menu show];
//        menu.YHChooseTabMenuCellBlock = ^(NSString * _Nonnull title) {
//            NSInteger is_public = 0;
//            if ([title isEqualToString:@"公司"]) {
//                weakSelf.type = @"1";
//                is_public = 1;
//            }else {
//                weakSelf.type = @"0";
//                is_public = 0;
//            }
//            [weakSelf loadDataArray:is_public];
//
//        };
    }else if ([title isEqualToString:@"注册时间"]) {
        [self.dateAlert show];
    }else if ([title isEqualToString:@"省市区/县2"]) {
        self.selAddressType = 2;
        [self laodAddress];
    }else if ([title isEqualToString:@"省市区/县3"]) {
        self.selAddressType = 3;
        [self laodAddress];
    }else if ([title isEqualToString:@"银行名称"]) {
        [self laodBanks:1];
    }
}

- (id<YWAlertViewProtocol>)dateAlert{
    if (!_dateAlert) {
        WS(weakSelf)
        _dateAlert = [YWAlertView alertViewWithTitle:@"注册时间" preferredStyle:YWAlertViewStyleDatePicker2 footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowYearMonthDay cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id  _Nullable value) {
            if (!value || buttonIndex == 100) {
                return;
            }
            weakSelf.company_open_date = [NSString stringWithFormat:@"%@",value];
            [weakSelf.tableView reloadData];
        }];
    }
    return _dateAlert;
}


-(void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == self.nameTextField) {
        self.name = textField.text;
    }
    if (textField == self.identityTextField) {
        self.identity = textField.text;
    }
    if (textField == self.addressTextField) {
        self.address = textField.text;
    }
    
    if (textField == self.companyNameTextField) {
        self.company_name = textField.text;
    }
    if (textField == self.companyBoosNameTextField) {
        self.company_legal_person = textField.text;
    }
    if (textField == self.companyCodeTextField) {
        self.company_business = textField.text;
    }
    if (textField == self.companyMoneyTextField) {
        self.company_capital = textField.text;
    }
    if (textField == self.companyAddressField) {
        self.company_address = textField.text;
    }
    
    if (textField == self.bankZhihangField) {
        self.bank_zhihang = textField.text;
    }
    if (textField == self.bankNumberField) {
        self.bank_number = textField.text;
    }
    if (textField == self.bankMobileField) {
        self.bank_mobile = textField.text;
    }
    if (textField == self.bankUserNameField) {
        self.bank_userName = textField.text;
    }

    if (textField == self.aliNameField) {
        self.ali_name = textField.text;
    }
    if (textField == self.aliNumberField) {
        self.ali_number = textField.text;
    }

    
}

-(void)setCellFieldContent:(UIView *)contentView title:(NSString *)title content:(NSString *)content isLine:(BOOL)isLine {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    contentView.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
    
    UILabel *titLabel = [UILabel ha_NLabelWithFont:16 textColor:@"#111a34" text:title alignment:0];
    [contentView addSubview:titLabel];
    [titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(88);
    }];
    
    UITextField *textField = [[UITextField alloc]init];
    textField.delegate = self;
    textField.textColor = [UIColor colorWithHexString:@"#121B32"];
    textField.font = [UIFont systemFontOfSize:16];
    textField.textAlignment = 2;
    [contentView addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-20);
        make.left.mas_equalTo(titLabel.mas_right);
        make.height.mas_offset(32);
    }];
    
    if (isLine == YES) {
        UIView *lineView = [UIView ha_createView];
        lineView.backgroundColor = [UIColor kLineColor];
        [contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(contentView).offset(20);
            make.right.equalTo(contentView).offset(-20);
            make.height.equalTo(@0.6);
            make.bottom.equalTo(contentView);
        }];
    }
    
    textField.text = content;
    
    if ([title isEqualToString:@"代理名称"]) {
        self.nameTextField = textField;
        textField.placeholder = @"请输入代理名称";
    }
    if ([title isEqualToString:@"身份证号"]) {
        self.identityTextField = textField;
        textField.placeholder = @"请输入身份证号";
    }
    if ([title isEqualToString:@"街道地址"]) {
        self.addressTextField = textField;
        textField.placeholder = @"请输入街道地址";
    }
    if ([title isEqualToString:@"企业名称"]) {
        self.companyNameTextField = textField;
        textField.placeholder = @"企业名称";
    }
    if ([title isEqualToString:@"法人姓名"]) {
        self.companyBoosNameTextField = textField;
        textField.placeholder = @"法人姓名";
    }
    if ([title isEqualToString:@"机构代码"]) {
        self.companyCodeTextField = textField;
        textField.placeholder = @"组织机构代码";
    }
    if ([title isEqualToString:@"注册资本"]) {
        self.companyMoneyTextField = textField;
        textField.placeholder = @"注册资本(万元)";
    }
    if ([title isEqualToString:@"公司地址"]) {
        self.companyAddressField = textField;
        textField.placeholder = @"公司详细地址";
    }
    
    if ([title isEqualToString:@"收款支行"]) {
        self.bankZhihangField = textField;
        textField.placeholder = @"收款支行";
    }
    
    if ([title isEqualToString:@"收款卡号"]) {
        self.bankNumberField = textField;
        textField.placeholder = @"收款卡号";
    }
    
    if ([title isEqualToString: @"结算法人"]) {
        self.bankUserNameField = textField;
        textField.placeholder = @"结算法人";
        textField.enabled = [NSString isEmptyString:self.bank_userName];
    }

    if ([title isEqualToString: @"预留手机号"]) {
        self.bankMobileField = textField;
        textField.placeholder = @"预留手机号";
    }

    
    if ([title isEqualToString: @"收款人名称"]) {
        self.aliNameField = textField;
        textField.placeholder = @"收款人名称";
        textField.enabled = [NSString isEmptyString:self.ali_name];
    }
    
    if ([title isEqualToString: @"支付宝账号"]) {
        self.aliNumberField = textField;
        textField.placeholder = @"支付宝账号";
    }

}

-(void)setCellTextContent:(UIView *)contentView title:(NSString *)title content:(NSString *)content isLine:(BOOL)isLine {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    if ([title isEqualToString:@"企业信息"] || [title isEqualToString:@"银联账户"] || [title isEqualToString:@"支付宝账户"]) {
        contentView.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
    }else {
        contentView.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
    }
    
    UILabel *titLabel = [UILabel ha_NLabelWithFont:16 textColor:@"#111a34" text:title alignment:0];
    [contentView addSubview:titLabel];
    [titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(88);
    }];
    
    UILabel *conLabel = [UILabel ha_BLabelWithFont:16 textColor:@"#888888" text:content alignment:2];
    [contentView addSubview:conLabel];
    [conLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-20);
        make.left.mas_equalTo(titLabel.mas_right);
        make.height.mas_offset(32);
    }];
    
    if (isLine == YES) {
        UIView *lineView = [UIView ha_createView];
        lineView.backgroundColor = [UIColor kLineColor];
        [contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(contentView).offset(20);
            make.right.equalTo(contentView).offset(-20);
            make.height.equalTo(@0.6);
            make.bottom.equalTo(contentView);
        }];
    }
    
}


-(void)setCellMit:(UIView *)contentView {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    contentView.backgroundColor = [UIColor khaBGColor];
    
    UIButton *mitButton = [[UIButton alloc]init];
    [mitButton setTitle:@"提交" forState:UIControlStateNormal];
    [mitButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
    mitButton.titleLabel.font = [UIFont systemFontOfSize:20];
    mitButton.backgroundColor = [UIColor colorWithHexString:@"#19191A"];
    [mitButton addTarget:self action:@selector(mitButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:mitButton];
    [mitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-25);
        make.centerY.mas_equalTo(0);
        make.height.mas_offset(54);
    }];
}


- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        // 去掉滚动条
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        // 设置背景颜色
        _tableView.backgroundColor = [UIColor khaBGColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array ];
    }
    return _dataArray;
}


-(void)laodAddress {
    WS(weakSelf)
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodGET;
    request.requestUrl = @"region/lists.html";
    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                NSArray *arr = [HAAddressProvinceMo mj_objectArrayWithKeyValuesArray:dataModel.data];
                
                HAAddressPopView *menu = [[HAAddressPopView alloc]initWithDZArray:arr];
                [menu show];
                menu.HAAddressPopViewSureBlock = ^(NSString * _Nonnull province, NSString * _Nonnull city, NSString * _Nonnull area) {
                    if (weakSelf.selAddressType == 1) {
                        weakSelf.region = [NSString stringWithFormat:@"%@/%@/%@",province,city,area];
                    }else if (weakSelf.selAddressType == 2) {
                        weakSelf.company_region = [NSString stringWithFormat:@"%@/%@/%@",province,city,area];
                    }else if (weakSelf.selAddressType == 3) {
                        weakSelf.bank_region = [NSString stringWithFormat:@"%@/%@/%@",province,city,area];
                    }
                    [weakSelf.tableView reloadData];
                };
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];
}

-(void)laodBanks:(NSInteger)type {
    WS(weakSelf)
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodGET;
    request.requestUrl = @"index/banks";
    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                NSArray *arr = [HABankMo mj_objectArrayWithKeyValuesArray:dataModel.data];
                NSMutableArray *dicts = [NSMutableArray array];
                for (HABankMo *mo in arr) {
                    [dicts addObject:@{@"color":@"#373737",@"title":mo.name?:@""}];
                }
                HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"选择开户银行"];
                [menu show];
                menu.YHChooseTabMenuCellBlock = ^(NSString * _Nonnull title) {
                    for (HABankMo *mo in arr) {
                        if ([title isEqualToString:mo.name]) {
                            if (type == 1) {
                                weakSelf.selBankModel = mo;
                            }
                            break;
                        }
                    }
                    [weakSelf.tableView reloadData];
                };
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];
}


@end
